import java.util.HashMap;
import java.util.Stack;

/**
 * @author 郝文雪
 * @date 2022/7/25 12:10
 * @Description Test
 */
public class func {
    public static void main(String[] args) {
        String s="()[]{}[";
        System.out.println(isVaild(s));
    }
    private static boolean isVaild(String s){
        HashMap<Character,Character> map=new HashMap<>();
        map.put(')','(');
        map.put(']','[');
        map.put('}','{');

        Stack<Character> stack=new Stack<>();

        for(int i=0;i<s.length();i++){
            char c=s.charAt(i);
            if(map.containsKey(c)){
                char c2=stack.isEmpty()?'#': stack.pop();
                if(c2!=map.get(c)){
                    return false;
                }
            }else{
                stack.push(c);
            }
        }
        return stack.isEmpty();
    }
}
